1
|
|
|
module.exports = function(GedcomX){ |
2
|
|
|
|
3
|
|
|
var utils = require('../utils'), |
4
|
|
|
AtomCommon = require('./AtomCommon'); |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* The agent used to generate a feed |
8
|
|
|
* |
9
|
|
|
* @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec} |
10
|
|
|
* @see {@link https://tools.ietf.org/html/rfc4287#section-4.2.4|RFC 4287} |
11
|
|
|
* |
12
|
|
|
* @class AtomGenerator |
13
|
|
|
* @extends AtomCommon |
14
|
|
|
* @param {Object} [json] |
15
|
|
|
*/ |
16
|
|
|
var AtomGenerator = function(json){ |
17
|
|
|
|
18
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
19
|
|
|
if(!(this instanceof AtomGenerator)){ |
20
|
|
|
return new AtomGenerator(json); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
24
|
|
|
if(AtomGenerator.isInstance(json)){ |
25
|
|
|
return json; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
this.init(json); |
|
|
|
|
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
AtomGenerator.prototype = Object.create(AtomCommon.prototype); |
32
|
|
|
|
33
|
|
|
AtomGenerator._gedxClass = AtomGenerator.prototype._gedxClass = 'GedcomX.AtomGenerator'; |
34
|
|
|
|
35
|
|
|
AtomGenerator.jsonProps = [ |
36
|
|
|
'uri', |
37
|
|
|
'version', |
38
|
|
|
'value' |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Check whether the given object is an instance of this class. |
43
|
|
|
* |
44
|
|
|
* @param {Object} obj |
45
|
|
|
* @returns {Boolean} |
46
|
|
|
*/ |
47
|
|
|
AtomGenerator.isInstance = function(obj){ |
48
|
|
|
return utils.isInstance(obj, this._gedxClass); |
49
|
|
|
}; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Initialize from JSON |
53
|
|
|
* |
54
|
|
|
* @param {Object} |
|
|
|
|
55
|
|
|
* @return {AtomGenerator} this |
56
|
|
|
*/ |
57
|
|
|
AtomGenerator.prototype.init = function(json){ |
58
|
|
|
|
59
|
|
|
AtomCommon.prototype.init.call(this, json); |
60
|
|
|
|
61
|
|
|
if(json){ |
62
|
|
|
this.setUri(json.uri); |
63
|
|
|
this.setVersion(json.version); |
64
|
|
|
this.setValue(json.value); |
65
|
|
|
} |
66
|
|
|
return this; |
67
|
|
|
}; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Set the uri |
71
|
|
|
* |
72
|
|
|
* @param {String} uri |
73
|
|
|
* @return {AtomGenerator} this |
74
|
|
|
*/ |
75
|
|
|
AtomGenerator.prototype.setUri = function(uri){ |
76
|
|
|
this.uri = uri; |
77
|
|
|
return this; |
78
|
|
|
}; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the uri |
82
|
|
|
* |
83
|
|
|
* @return {String} this |
84
|
|
|
*/ |
85
|
|
|
AtomGenerator.prototype.getUri = function(){ |
86
|
|
|
return this.uri; |
87
|
|
|
}; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Set the version |
91
|
|
|
* |
92
|
|
|
* @param {String} version |
93
|
|
|
* @return {AtomGenerator} this |
94
|
|
|
*/ |
95
|
|
|
AtomGenerator.prototype.setVersion = function(version){ |
96
|
|
|
this.version = version; |
97
|
|
|
return this; |
98
|
|
|
}; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the version |
102
|
|
|
* |
103
|
|
|
* @return {String} this |
104
|
|
|
*/ |
105
|
|
|
AtomGenerator.prototype.getVersion = function(){ |
106
|
|
|
return this.version; |
107
|
|
|
}; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Set the value |
111
|
|
|
* |
112
|
|
|
* @param {String} value |
113
|
|
|
* @return {AtomGenerator} this |
114
|
|
|
*/ |
115
|
|
|
AtomGenerator.prototype.setValue = function(value){ |
116
|
|
|
this.value = value; |
117
|
|
|
return this; |
118
|
|
|
}; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get the value |
122
|
|
|
* |
123
|
|
|
* @return {String} this |
124
|
|
|
*/ |
125
|
|
|
AtomGenerator.prototype.getValue = function(){ |
126
|
|
|
return this.value; |
127
|
|
|
}; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Export the object as JSON |
131
|
|
|
* |
132
|
|
|
* @return {Object} JSON object |
133
|
|
|
*/ |
134
|
|
|
AtomGenerator.prototype.toJSON = function(){ |
135
|
|
|
return this._toJSON(AtomCommon, AtomGenerator.jsonProps); |
136
|
|
|
}; |
137
|
|
|
|
138
|
|
|
GedcomX.AtomGenerator = AtomGenerator; |
139
|
|
|
|
140
|
|
|
}; |